package com.thymeleaf;

import service.ActorService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/save.do")
public class ActorSave extends HttpServlet {

    private ActorService actorService = new ActorService();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");

        String name = req.getParameter("name");
        String sex = req.getParameter("sex");
        String phone = req.getParameter("phone");

        boolean add = actorService.add(name, sex, phone);
        if (add) {
            resp.sendRedirect("list");
        } else {
            System.out.println("添加失败");
        }

    }
}
